package com.itrip.search.controller;

import com.itrip.search.config.Page;
import com.itrip.search.service.SearchHotelService;
import com.itrip.search.vo.ItripHotelVO;
import com.itrip.search.vo.SearchHotCityVO;
import com.itrip.search.vo.SearchHotelVO;
import com.itrip.utils.dto.Dto;
import com.itrip.utils.util.EmptyUtils;
import com.itrip.utils.vo.DtoUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查询酒店的controller
 * Created by XX on 17-5-10.
 */
@RestController
@RequestMapping("/search/api/hotellist")
public class HotelListController {

    @Autowired
    private SearchHotelService searchHotelService;

    /***
     * 搜索酒店分页
     *
     * @param vo
     * @return
     * @throws Exception
     */

    @PostMapping("/searchItripHotelPage")
    public Dto<Page<ItripHotelVO>> searchItripHotelPage(@RequestBody SearchHotelVO vo) {
        Page page = null;
        if (EmptyUtils.isEmpty(vo) || EmptyUtils.isEmpty(vo.getDestination())) {
            return DtoUtil.returnFail("目的地不能为空");
        }
        try {
            page = searchHotelService.searchItripHotelPage(vo, vo.getPageNo(), vo.getPageSize());
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败");
        }
        return DtoUtil.returnDataSuccess(page);
    }

    @PostMapping("/searchItripHotelListByHotCity")
    public Dto<Page<ItripHotelVO>> searchItripHotelListByHotCity(@RequestBody SearchHotCityVO vo) throws Exception {
        if (EmptyUtils.isEmpty(vo) || EmptyUtils.isEmpty(vo.getCityId())) {
            return DtoUtil.returnFail("城市id不能为空");
        }
        Map<String, Object> param = new HashMap<>();
        param.put("cityId", vo.getCityId());
        List<ItripHotelVO> list = searchHotelService.searchItripHotelListByHotCity(vo.getCityId(), vo.getCount());
        return DtoUtil.returnDataSuccess(list);
    }
}
